package com.clouddot.baipai.ui.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.clouddot.baipai.R;
import com.clouddot.baipai.infrastructure.environment.Env;
import com.clouddot.baipai.infrastructure.environment.Environment;
import com.clouddot.baipai.infrastructure.environment.initial.InitialAppContext;
import com.clouddot.baipai.ui.util.ToastUtil;

/**
 * Created by wxy on 2018/4/10.
 */

public class A_Set3Fragment extends BaseFragment implements View.OnClickListener{

    private View view;
    private LinearLayout isEsit;
    private EditText editText;
    private Activity activity;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        return view;
    }

    @Override
    protected void setContentView() {
        super.setContentView();
        if(Environment.getInstance().Height <= 100) {
            view = LayoutInflater.from(activity).inflate(R.layout.h_f_set3fg, null);
        }else {
            view = LayoutInflater.from(activity).inflate(R.layout.v_f_set3fg, null);
        }
    }

    @Override
    protected void initControls() {
        super.initControls();
        isEsit = view.findViewById(R.id.btn2);
        editText = view.findViewById(R.id.host1);
        editText.setText(Env.getAppContext().password);
    }

    @Override
    protected void setListener() {
        super.setListener();
        isEsit.setOnClickListener(this);
    }

    @Override
    protected void loadParams() {
        super.loadParams();
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.activity = activity;

    }

    @Override
    public void onResume() {
        super.onResume();
        if (Env.getAppContext().isInitial) {
            runThreadAction("getAllClass");
        }
    }

    @Override
    public void onPause() {
        super.onPause();

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn2:
                setIsEsit();
                break;

        }
    }

    private void setIsEsit(){
        if(TextUtils.isEmpty(editText.getText().toString())){
            ToastUtil.showToast(activity,"密码不能为空");
            return;
        }
        Env.getHelper().put("password",editText.getText().toString());
        ToastUtil.showToast(activity,"保存成功");

        try {
            new InitialAppContext(Environment.getInstance()).reinitial();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
